// Borrowed from http://www.w3schools.com/xsl/xsl_client.asp & course slides
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xslLocation = document.getElementById("get_stylesheet").value;
xslLocation = "xsl/" + xslLocation + ".xsl";
xml=loadXMLDoc("StudentTimetable");
xsl=loadXMLDoc(xslLocation);
// code for IE
if (window.ActiveXObject)
  {
	ex=xml.transformNode(xsl);
  document.getElementById("timetable_container").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById("timetable_container").appendChild(resultDocument);
  }
}

function checkTimeTable()
{
	var checkOptions = document.getElementsByName("XSLToption");
	var flag = false;
	var index = 0;
	
	for (var i = 0 ; i < checkOptions.length ; i++)
	{
		if (checkOptions[i].checked)
		{
			flag = true;
			index = i;
			break;
		}
	}
	if (false == flag)
	{
		alert("You haven't checked any of the options...");
		return false;
	}
	
	if (checkOptions[index].value == "3")
	{
		var fileField = document.getElementById("XSLTfile");
		if (null == fileField.value || fileField.value.length == 0)
		{
			alert("You haven't chosen a file!");
			return false;
		}
	}
	return true;
}

function imageCheck(imageId)
{
	var checkedElement = document.getElementById(imageId);
	
	if (checkedElement.value == null || checkedElement.value.length == 0)
	{
		alert("Please insert a picture to upload...");
		return false;
	}
	return true;
}